#include "dattype_lab.h"

DatType_Lab::DatType_Lab(QWidget *parent) : QLabel(parent)
{

}

void DatType_Lab::mousePressEvent(QMouseEvent *e)
{
    if (e->button() == Qt::LeftButton)
    {
        //**********************************************************获取信息
        QString Style = this->styleSheet();
        QString Text  = this->text();
        //**********************************************************生成图标
        QPixmap pixmap(this->size());
        this->render(&pixmap);
        //**********************************************************构建信息流
        QByteArray itemData;
        QDataStream dataStream(&itemData, QIODevice::WriteOnly);
        dataStream << Style << Text;

        QMimeData *mimeData = new QMimeData;
        mimeData->setData("DataType", itemData);
        //**********************************************************执行拖拽
        QDrag *drag = new QDrag(this);
        drag->setMimeData(mimeData);
        drag->setPixmap(pixmap);
        drag->setHotSpot(QPoint(this->rect().center().x(),this->rect().center().y()-20));
        drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
    }
    QLabel::mousePressEvent(e);
}

